﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using ShootSearch.Core;
using ShootSearch.FileSystem;
using System.Diagnostics;
using ShootSearch.Util.Serializers;

namespace ShootSearch.Tests.FileSystem
{
    [TestFixture]
    public class FileObjectTextTests
    {
        public static void Run()
        {
            FileObjectTextTests obj = new FileObjectTextTests();
            obj.CreateTests();
            obj.SerializedTest();
        }

        private FileObjectText GetObjectItem()
        {
            FileObjectText obj = new FileObjectText();
            obj.Url = "http://www.shootsoft.net";
            obj.DateTime = DateTime.Now;
            obj.Add("Title", "a title");
            obj.Add("Content", "ShootSearch content");
            return obj;
        }

        [Test]
        public void CreateTests()
        {
            FileObjectText expected = GetObjectItem();
            FileObject fe = expected.GetFileObject();
            FileObjectText actual = new FileObjectText(fe);
            Assert.AreEqual(expected["Content"], actual["Content"]);


        }

        [Test]
        public void SerializedTest()
        {
            FileObjectText expected = GetObjectItem();
            string xml = XmlFormatter.ToXml(expected);
            FileObjectText actual = XmlFormatter.FromXml(xml, expected.GetType()) as FileObjectText;
            Debug.WriteLine(xml);
            Assert.AreEqual(expected["Content"], actual["Content"]);


        }
    
    }
}
